<script setup>
import { onBeforeMount,ref } from 'vue';
import { getDaemonSetDetailHandler as getDetail } from '../../api/daemonset.js';
import { useRoute } from 'vue-router';
import { useItem } from '../../store';
import CreateOrEdit from './CreateOrEdit.vue';
const route = useRoute()
const useItemer = useItem()
let showEdit = ref(false)
// 1. 获取当前编辑的资源配置
onBeforeMount(async ()=>{
  // 获取请求参数
  //例如http://example.com/deployment/edit?clusterId=123&namespace=default 
  // clusterId=123&namespace=default
  const requestQuery =  route.query
  await getDetail(requestQuery).then((res)=>{
    console.log("获取资源配置:",res.data.data.item)
    // 2. 把当前数据赋值给pinia
    useItemer.item = JSON.parse(JSON.stringify(res.data.data.item))
    //如果item是rollingUpdate
    if(useItemer.item.spec.updateStrategy.type === 'RollingUpdate' && useItemer.item.spec.updateStrategy.rollingUpdate === undefined){
      useItemer.item.spec.updateStrategy.rollingUpdate = {}
    }
    showEdit.value = true
  })
})
</script>

<template>
  <CreateOrEdit v-if="showEdit" 
  :method="route.query.method" 
  resource-type="DaemonSet">
  </CreateOrEdit>
</template>

<style scoped>

</style>
